/**
 * Kernel.h
 * Description: Kernel header file.
 * Authors: Hamish Cumming, Brian Thorne 2008
 */

#ifndef KERN_H
#define KERN_H

#include "global.h"

//The Maximum number of tasks the kernel supports
#define MAX_NUM_TASKS 10



/* Function Prototypes */
/**
 * Initialise the kernel
 * @return Exit status
 */
uint8_t kernel_init (void);

/**
 * Runs the kernel; starts round robin task scheduling
  * @return Exit status
 */
uint8_t kernel_run (void);

/**
 * Register a backgroung task for scheduling
 * @param task The task to register
 * @param task_index The unique identifier for the task
 * @return exit success or fail.
 */
uint8_t register_task (uint8_t (*task) (void), uint8_t task_index);

/**
 * Activates a background task
 * @param index of task to activate.
 * @return exit status
 */
uint8_t activate_task (uint8_t task_index);

/**
 * Deactivates a background task
 * @param index of task to deactivate
 * @return exit status
 */
uint8_t deactivate_task (uint8_t task_index);

/**
 * Get the value of the real time clock
 * @return The current time
 */
time_t get_clock_value(void);

/* Global Data */
enum bgnd_tasks {JOYSTICK_TASK = 0, MEASURE_TASK, REPLAY_TASK, DISPLAY_TASK, RESET_STATS_TASK};
enum task_state {DEACTIVATED = 0, ACTIVATED};
extern volatile uint8_t task_flags[MAX_NUM_TASKS]; //global, for ISR's to modify

#endif
